<?php


class App_Controllers_video
{
    private $_template;
    private $_models = array();

    public function index()
    {

        $this->_models['video'] = new App_Models_Video();
        $this->_template = new Core_Template();

        $this->_template->add_css_file(array('/App/Views/index.css',
                                             '/App/Views/video/video.css'
                                       ));



        $this->_template->set_title("Видео");
        $this->_template->get_smarty()->assign('title',$this->_template->get_title());
        $this->_template->get_smarty()->assign('css_file',$this->_template->get_css_file());

        $this->_template->get_smarty()->assign('videos',$this->_models['video']->get_videos());
        $this->_template->get_smarty()->assign('content','video/videos');
        
        $this->_template->get_smarty()->display('index.tpl');
    }

    public function view(Core_Request $request)
    {

        $this->_models['comments'] = new App_Models_Comment();
        $this->_models['video'] = new App_Models_Video();

        $this->_template = new Core_Template();

        $this->_template->add_css_file(array('/App/Views/index.css',
                                             '/App/Views/video/video.css',
                                             '/App/Views/comment/comment.css'
                                       ));



        $this->_template->add_js_file(array(
        		'/App/Views/js/ajax.js',
        		'/App/Views/js/jquery.js',
        		'/App/Views/js/comment.js',
        		'/App/Views/js/jquery.corner.js'
        ));
                                       
        $this->_template->set_title("Видео");
        $this->_template->get_smarty()->assign('title',$this->_template->get_title());
        $this->_template->get_smarty()->assign('css_file',$this->_template->get_css_file());
                $this->_template->get_smarty()->assign('js_file',$this->_template->get_js_file());
        $video = $this->_models['video']->get_video($request->params['id']);

        if ($video) {
            $this->_template->get_smarty()->assign('video',$video[0]);
            $comments = $this->_models['comments']->get_comments("videocomment","video_id",$request->params['id']);
            $this->_template->get_smarty()->assign('comments',$comments);

        }

        $this->_template->get_smarty()->assign('content','video/video');

        $this->_template->get_smarty()->display('index.tpl');
    }


    public function add_comment()
    {

        if ((isset($_POST['author'])) && (isset($_POST['text'])) && (isset($_POST['email']))) {
            if ((!empty($_POST['author'])) && (!empty($_POST['text'])) && (!empty($_POST['email']))) {
                $this->_models['comment'] = new App_Models_Comment();
                $this->_models['comment']->add_comment("videocomment","video_id",$_GET['id'], $_POST['author'], $_POST['email'], $_POST['text']);

                echo  $_POST['author']."|#|". date("Y-m-d H:i:s")."|#|". $_POST['text'];
            } else {
                echo "1|#|none|#|2";
            }
        }

    }
    public function __call($name, $args)
    {
        $this->_template = new Core_Template();
        $this->_template->error_page();
    }

    
}


?>
